package 接力赛跑;

public class RunThread1 {
    private static int count=1000;


    public synchronized static void show(){
        if (count>0){
            System.out.println(Thread.currentThread().getName()+"拿到接力棒");
            for (int i = 1; i <=10 ; i++) {
                System.out.println(Thread.currentThread().getName()+"跑了"+(10*i)+"米");
            }
        }
    }

    public static void main(String[] args) {

        for (int i = 1; i <=10 ; i++) {
            new Thread(()->{
                while (true){
                    show();
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    count-=100;
                    if (count==0){
                        System.out.println("已经到终点了");
                        break;
                    }
                    return;

                }
            },i+"号选手").start();
        }
    }
}
